<?php
class EmailValidator extends Validator
{
	public function validate(Validatable $field)
	{
		if($field->getValue()=='' && !$this->required)
		{
			return true;
		}
		
		if(parent::validate($field))
		{
			if(preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $field->getValue()) != 1)
			{
				$field->setError('is geen geldig e-mailadres');
				return false;
			}
			return true;
		}
		return false;
	}
}